|
1
|
|
|
// Copyright © 2017 TangDongxin |
|
2
|
|
|
|
|
3
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining |
|
4
|
|
|
// a copy of this software and associated documentation files (the "Software"), |
|
5
|
|
|
// to deal in the Software without restriction, including without limitation |
|
6
|
|
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense, |
|
7
|
|
|
// and/or sell copies of the Software, and to permit persons to whom the |
|
8
|
|
|
// Software is furnished to do so, subject to the following conditions: |
|
9
|
|
|
|
|
10
|
|
|
// The above copyright notice and this permission notice shall be included |
|
11
|
|
|
// in all copies or substantial portions of the Software. |
|
12
|
|
|
|
|
13
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
14
|
|
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
15
|
|
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
|
16
|
|
|
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
|
17
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
|
18
|
|
|
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE |
|
19
|
|
|
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
20
|
|
|
|
|
21
|
|
|
// =========================================== |
|
22
|
|
|
// JSON PARSER |
|
23
|
|
|
// =========================================== |
|
24
|
|
|
function onParse(result) { |
|
|
|
|
|
|
25
|
|
|
var chrome = this.chrome || this.browser; |
|
|
|
|
|
|
26
|
|
|
var jsonRe = /^\s*(?:\[\s*(?=-?\d|true|false|null|["[{])[^]*\]|\{\s*"[^]+\})\s*$/; |
|
27
|
|
|
var body = document.body; |
|
28
|
|
|
var str, jsonpMatch, tag; |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
console.log(strictOnly); |
|
|
|
|
|
|
31
|
|
|
if (strictOnly) { |
|
|
|
|
|
|
32
|
|
|
// only render when the contentType is json |
|
33
|
|
|
if (/[+\/]json$/i.test(document.contentType)) { |
|
34
|
|
|
init(); |
|
35
|
|
|
str = body.textContent; |
|
36
|
|
|
draw(str, body); |
|
37
|
|
|
} |
|
38
|
|
|
} else { |
|
39
|
|
|
// check whether the content is json or like json |
|
40
|
|
|
try { |
|
41
|
|
|
if (jsonRe.test(body.textContent)) { |
|
42
|
|
|
init(); |
|
43
|
|
|
draw(first.textContent, body); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
} catch (e) { |
|
46
|
|
|
dlog(e); |
|
47
|
|
|
// ignore |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
function init() { |
|
52
|
|
|
if (tag) { |
|
53
|
|
|
return; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
tag = document.createElement("style"); |
|
57
|
|
|
tag.textContent = [ |
|
58
|
|
|
'.R', ',.D', '{font:' + fontSize + ' ' + fontStyle + '}' + |
|
|
|
|
|
|
59
|
|
|
'.D', '{margin-left:0.5em; padding-left:2em; margin-top: 1px; border-left:1px dashed; border-color: #93A1A1;}' + |
|
60
|
|
|
'.X', '{border:1px solid #ccc; padding:1em}' + |
|
61
|
|
|
'a.L', '{text-decoration:none}' + |
|
62
|
|
|
'a.L', ':hover,a.L', ':focus{text-decoration:underline}' + |
|
63
|
|
|
'i.I', '{cursor:pointer;color:#ccc}' + |
|
64
|
|
|
'i.H', ',i.I', ':hover{text-shadow: 1px 1px 3px #999; color:#333}' + |
|
65
|
|
|
'i.I', ':before{content:" ▼ "}' + |
|
66
|
|
|
'i.C', ':before{content:" ▶ "}' + |
|
67
|
|
|
'i.C', '+.D', '{width:1px; height:1px; margin:0; padding:0; border:0; display:inline-block; overflow:hidden}' + |
|
68
|
|
|
'.S', '{color:' + strColor + '}' + // string |
|
|
|
|
|
|
69
|
|
|
'.K', '{color:' + keyColor + '}' + // key |
|
|
|
|
|
|
70
|
|
|
'.E', '{color:#BCADAD}' + // error |
|
71
|
|
|
'.B', '{color:' + intColor + '}' + // number and bool |
|
|
|
|
|
|
72
|
|
|
'.E', ',.B', '{font-style: italic}' + // number bold |
|
73
|
|
|
'h3.E', '{margin:0 0 1em}' |
|
74
|
|
|
].join(RAND); |
|
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
tag.textContent += 'i.I' + RAND + ':after{content:attr(data-content)}'; |
|
77
|
|
|
tag.textContent += 'body {background: ' + bgColor + '; color:' + defaultColor + ';}'; |
|
|
|
|
|
|
78
|
|
|
tag.textContent += '.HIDE {width:200px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }'; |
|
79
|
|
|
tag.textContent += '* {font:' + fontSize + ' ' + fontStyle + ' !important;}'; |
|
80
|
|
|
tag.textContent += '.black_overlay{ display: none; position: fixed; top: 0%; left: 0%; width: 100%; height: 100%; background-color: black; z-index:1001; -moz-opacity: 0.6; opacity:.60; filter: alpha(opacity=60); }'; |
|
81
|
|
|
tag.textContent += '.white_content { display: none; position: fixed; top: 10%; left: 13%; width: 70%; min-width: 500px; min-height: 300px; height: 60%; padding: 1%; border: 16px solid orange; background-color: white; z-index:1002; overflow: auto; }'; |
|
82
|
|
|
tag.textContent += 'str:hover{text-shadow: 1px 1px 3px #999; color:#333}'; |
|
83
|
|
|
tag.textContent += 'json:hover{text-shadow: 1px 1px 3px #999; color:#333}'; |
|
84
|
|
|
|
|
85
|
|
|
document.head.appendChild(tag); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.